package zero.tech.def.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import zero.tech.def.DefFactory;

@Configuration
@ConfigurationProperties(prefix = "def.xml")
@ConditionalOnProperty(prefix = "def.xml",name = "enable",matchIfMissing = false)
public class DefConfiguration {
	private boolean enable;
	private String xmlPackage;
	public String getXmlPackage() {
		return xmlPackage;
	}
	public void setXmlPackage(String xmlPackage) {
		this.xmlPackage = xmlPackage;
	}
	public boolean isEnable() {
		return enable;
	}
	public void setEnable(boolean enable) {
		this.enable = enable;
	}
	protected class DefInit{
		
	}
	@Bean("initdef")
	public DefInit init() {
		try {
			assert(xmlPackage!=null&&!"".equals(xmlPackage));
			DefFactory.getFactory().start(xmlPackage);
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
		return new DefInit();
	}
}
